import 'package:flutter/material.dart';

//IndexedStack继承自Stack，它的作用是显示第index个child，其他child都是不可见的。
// 所以IndexedStack的尺寸永远是跟最大的子节点尺寸一致。
class IndexedStackWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _IndexedStackWidgetState();
  }
}
class _IndexedStackWidgetState extends State<IndexedStackWidget> {
  var _index = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: new AppBar(
          title: new Text("IndexedStack"),
          leading: new BackButton(),
        ),
        body: Column(
          children: [
            new IndexedStack(
              //index设置为1,显示含文本的Container的节点
              index: _index,
              //(0,0)是中心, X:左为负右为正,Y:上为负下为正
              alignment: const Alignment(0.6, 0.6),
              children: <Widget>[
                CircleAvatar(
                  backgroundImage: AssetImage('assets/img/icon_header.jpg'),
                  radius: 100,
                ),
                Container(
                  padding: const EdgeInsets.all(2),
                  decoration: BoxDecoration(
                    color: Colors.black45,
                  ),
                  child: Text(
                    'Flutter',
                    style: TextStyle(
                        fontSize: 20,
                        fontWeight: FontWeight.bold,
                        color: Colors.white),
                  ),
                )
              ],
            ),

            ElevatedButton(onPressed: (){
              _index = (_index + 1) % 2;
              setState(() {

              });
            }, child: Text("切换"))
          ],
        ));
  }
}
